<?php

namespace backend\models\article;

use Yii;

/**
 * This is the model class for table "{{%edu_page}}".
 *
 * @property integer $page_id
 * @property string $page_title
 * @property integer $is_show
 * @property integer $page_status
 * @property integer $page_addtime
 * @property string $page_text
 * @property string $page_uname
 * @property string $page_url
 */
class Page extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%page}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        $user = yii::$app->user->identity;
        $user = $user->attributes;
        return [
            [['is_show', 'page_addtime'], 'integer'],
            [['page_text'], 'string'],
            [['page_title', 'page_uname'], 'string', 'max' => 50],
            [['page_title','page_url'], 'required'], 
            [['page_uname'],'default','value'=>$user['username']],
            [['page_addtime'],'default','value'=>time()],
            [['page_url'], 'string', 'max' => 100]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'page_id' => 'Page ID',
            'page_title' => '标题',
            'is_show' => '是否显示',
            'page_status' => '编辑器类型',
            'page_addtime' => 'Page Addtime',
            'page_text' => '正文',
            'page_uname' => 'Page Uname',
            'page_url' => 'Url路径',
        ];
    }
    //总条数
    public function PageCount()
    {
        return $this->find()
                    ->count();
    }
    /**
    * 搜索查询
    */
    public function PageSel($pagination)
    {
        return $this->find()
                ->orderBy(['page_addtime'=>SORT_DESC])
                ->offset($pagination->offset)
                ->limit($pagination->limit)
                ->asArray()
                ->all();
    }

    public function Page()
    {
        return $this->find()
                ->orderBy(['page_addtime'=>SORT_DESC])
                ->where(['=','is_show','1'])
                ->asArray()
                ->all();
    }
}
